// 函数柯理化，也是高阶函数的一种

// 判断变量的类型
// typeof,constructor,instanceof,Object.prototype.toString.call(target)

/* function isType(str, type) {
  return Object.prototype.toString.call(str) == `[object ${type}]`;
} */

function isType(type) {
  return function (val) {
    return Object.prototype.toString.call(val) == `[object ${type}]`;
  };
}
// 具体的方法 isNumber,isString
let utils = {};
['String', 'Number', 'Boolean'].forEach((item) => {
  utils['is' + item] = isType(item);
});

console.log(utils.isString('123'));
console.log(utils.isNumber(22));

function curring(fn, arr = []) {
  let len = fn.length;
  return function (...args) {
    let newArgs = [...arr, ...args];
    if (len === newArgs.length) {
      return fn(...newArgs);
    } else {
      return curring(fn, newArgs);
    }
  };
}

function sum(a, b, c) {
  console.log(a + b + c);
}

let newSum = curring(sum);

newSum(1, 2)(3);
